﻿// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;
using System.Windows.Media;

using Nova.CodeDOM;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.UnaryOperator"/>.
    /// </summary>
    public abstract class UnaryOperatorVM : OperatorVM
    {
        #region /* FIELDS */

        protected ExpressionVM _expressionVM;

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// Create a view model instance for the specified <see cref="CodeDOM.UnaryOperator"/>.
        /// </summary>
        protected UnaryOperatorVM(UnaryOperator unaryOperator, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(unaryOperator, dictionary)
        {
            _expressionVM = (ExpressionVM)CreateVM(unaryOperator.Expression, false, dictionary);
        }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.UnaryOperator"/> model.
        /// </summary>
        public UnaryOperator UnaryOperator
        {
            get { return (UnaryOperator)CodeObject; }
        }

        /// <summary>
        /// The associated <see cref="ExpressionVM"/>.
        /// </summary>
        public new ExpressionVM Expression
        {
            get { return _expressionVM; }
        }

        #endregion

        #region /* METHODS */

        #endregion

        #region /* RENDERING */

        protected override Brush RenderBrush(RenderFlags flags)
        {
            // If there is an unresolved operator overload, render it as an error (or warning if in a doc comment)
            return (UnaryOperator.HiddenRef is UnresolvedRef ? (flags.HasFlag(RenderFlags.InDocComment) ? WARNING_BRUSH : ERROR_BRUSH) : OPERATOR_BRUSH);
        }

        public override void RenderVisible(CodeRenderer renderer, RenderFlags flags)
        {
            base.RenderVisible(renderer, flags);
            _expressionVM.RenderVisible(renderer, flags);
        }

        public override void UnRender()
        {
            _expressionVM.UnRender();
            base.UnRender();
        }

        public override void RenderToolTip(CodeRenderer renderer, RenderFlags flags)
        {
            base.RenderToolTip(renderer, flags);
            if (UnaryOperator.HiddenRef != null)
            {
                renderer.NewLine();
                CreateVM(UnaryOperator.HiddenRef).RenderToolTip(renderer, RenderFlags.SuppressLineCol);
            }
        }

        #endregion
    }
}
